/**
 * Created by chengming on 18/5/27.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const iconv = require("iconv-lite");
const vm = require('vm');
const request = require('request-promise');
const logger = require('../../conf/logger');
const querystring = require("querystring")
const urlencode = require("urlencode")
const moment = require('moment')

/**
 * 北京互金网
 * @type {module.Bjp2p}
 */
module.exports = class HKEXLCIJson extends BaseJsonAdapter{

    async reqJson(){
        let contents = [];
        let url = 'https://www1.hkexnews.hk/ncms/json/eds/lcisehk1relsdc_1.json?_=' + moment().unix()

        let body = await this.doRequest();
        let decodeBody = iconv.decode(body, this.encoding).toString();
        let data = JSON.parse(decodeBody);
        if ( data && data.newsInfoLst) {
          for (let row of data.newsInfoLst) {
            for (let company of row.stock) {
              contents.push({
                title: company['sn'] + '(' + company['sc'] + '}' + row['title'],
                href: 'https://www1.hkexnews.hk' + row['webPath']
              });
            }
          }
        }
        return {data:contents}
    }
}
